#include "Bone.h"
#include "selfBoneManager.h"

Bone::Bone(stdBone std, Point* p)
{
	_std = std;
	_p = p;
	_remove = false;
	_nowRead = _nowFps = _nextFps = 0;
}

void Bone::updata()
{
	emenyMessage* m = 0;
	if (_nowRead == _std.event.size())
	{
		_remove = true;
	}
	if (_nowFps == _nextFps && _nowRead < _std.event.size())
	{
		m = _std.getMessage(_nowRead);
		_nowRead++;
		if (m != NULL)
		{
			if (m->flag == WAIT)
			{
				_nextFps += m->time;
			}else if (m->flag == SHOTBULLET && m->effect != ROUND)
			{
				int begin = m->angle;
				stdBulletLib* lib = 0;
				lib = lib->Instance();
				selfBoneManager* manager = 0;
				manager = manager->Instance();
				for (int i = 0; i < (int)m->ay; i++)
				{
					//cout << begin << endl;
					manager->add(lib->getBullet(m->kind),
						*_p, _p, begin);
					begin += (int)m->ax;
					begin = begin%360;
				}
				_nextFps += m->time;
			}else if (m->flag == SHOTBULLET && m->effect == ROUND)
			{
				int begin = m->angle;
				stdBulletLib* lib = 0;
				lib = lib->Instance();
				selfBoneManager* manager = 0;
				manager = manager->Instance();
				for (int i = 0; i < (int)m->ay; i++)
				{
					/*Bullet* b = new Bullet(lib->getBullet(m->kind),
						*_p, _p, begin, m->effect);
					b->setRound(_p);
					manager->add(b);
					begin += (int)m->ax;
					begin = begin%360;*/
				}
			}
		}
	}
	_nowFps++;
}